<!-- 退换票 -->
<template>
  <el-dialog
    :title="title"
    :visible.sync="visible"
    width="800px"
    @close="handleClose"
  >
    <el-form ref="form" :model="formData" label-width="120px" :rules="rules">
      <!-- 退费申请信息 -->
      <div class="apply-info-container">
        <h3>退费申请信息</h3>
        <div class="info-grid">
          <div class="info-item">
            <span class="label">发票状态：</span>
            <span class="value">
              <span>{{
                dict.invoice_status[Number(formData.exampleOne)]
              }}</span>
            </span>
          </div>
          <div class="info-item">
            <span class="label">发票种类：</span>
            <span class="value">
              <span>{{
                dict.invoice_category[Number(formData.preInvoiceCategory)]
              }}</span>
            </span>
          </div>
          <div class="info-item">
            <span class="label">发票类型：</span>
            <span class="value">
              <span>{{
                dict.invoice_type[Number(formData.preInvoiceType)]
              }}</span>
            </span>
          </div>
          <div class="info-item">
            <span class="label">姓名：</span>
            <span class="value">{{ formData.studentName }}</span>
          </div>
          <div class="info-item">
            <span class="label">单位：</span>
            <span class="value">{{ formData.unitName }}</span>
          </div>
          <div class="info-item">
            <span class="label">身份证号：</span>
            <span class="value">{{ formData.idNumber }}</span>
          </div>
          <div class="info-item">
            <span class="label">联系方式：</span>
            <span class="value">{{ formData.phonenumber }}</span>
          </div>
          <div class="info-item">
            <span class="label">报名类别：</span>
            <span class="value">
              <span>{{
                dict.registration_method[Number(formData.registrationMethod)]
              }}</span>
            </span>
          </div>
          <div class="info-item">
            <span class="label">培训班：</span>
            <span class="value">{{ formData.trainingClass }}</span>
          </div>
          <div class="info-item">
            <span class="label">费用：</span>
            <span class="value">{{ formData.projectSum }}</span>
          </div>
          <div class="info-item">
            <span class="label">退换票金额：</span>
            <span class="value">{{ formData.preInvoiceAmount }}</span>
          </div>
          <div class="info-item">
            <span class="label">退换票原因：</span>
            <span class="value">{{ formData.exampleTwo }}</span>
          </div>
        </div>
      </div>

      <!-- 审核选项 -->
      <div class="audit-section">
        <el-form-item label="是否通过退换票申请：">
          <el-radio-group v-model="formData.exampleOne">
            <el-radio label="4">通过</el-radio>
            <el-radio label="5">未通过</el-radio>
          </el-radio-group>
        </el-form-item>

        <el-form-item label="原因备注：" prop="reasonRemark">
          <el-input
            v-model="formData.reasonRemark"
            type="textarea"
            :rows="4"
            placeholder="请输入拒绝原因"
            maxlength="500"
            show-word-limit
          />
        </el-form-item>
      </div>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel">取消</el-button>
      <el-button type="primary" @click="handleSubmit">提交</el-button>
    </div>
  </el-dialog>
</template>

<script>
import DictTag from "@/components/DictTag";

export default {
  name: "RefundInvoiceDialog",
  components: {
    DictTag,
  },
  props: {
    title: {
      type: String,
      default: "退换票",
    },
    visible: {
      type: Boolean,
      default: false,
    },
    data: {
      type: Object,
      default: () => ({}),
    },
    dict: {
      type: Object,
      default: () => ({}),
    },
  },
  data() {
    return {
      formData: {
        exampleOne: "",
        preInvoiceCategory: "",
        preInvoiceType: "",
        studentName: "",
        unitName: "",
        creditCode: "",
        idNumber: "",
        phonenumber: "",
        applyTime: "",
        applicant: "",
        registrationMethod: "",
        registrationProject: "",
        trainingClass: "",
        trainingType: "",
        projectSum: "",
        examFee: "",
        preInvoiceAmount: "",
        exampleTwo: "",
        exampleOne: "4",
        reasonRemark: "",
      },
      rules: {},
    };
  },
  watch: {
    visible(val) {
      if (val) {
        this.initFormData();
      }
    },
  },
  methods: {
    initFormData() {
      // 将传入的数据填充到表单中
      this.formData = { ...this.data };
    },
    handleClose() {
      this.$emit("update:visible", false);
    },
    handleCancel() {
      this.$emit("update:visible", false);
    },
    handleSubmit() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.$emit("submit", this.formData);
          this.handleCancel();
        }
      });
    },
  },
};
</script>

<style scoped>
.apply-info-container {
  border: 1px solid #dcdfe6;
  padding: 20px;
  margin-bottom: 20px;
}

.apply-info-container h3 {
  margin-top: 0;
  color: #303133;
  font-size: 16px;
  margin-bottom: 15px;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 15px;
}

.info-item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
}

.label {
  font-weight: bold;
  min-width: 120px;
  color: #909399;
}

.value {
  flex: 1;
  color: #303133;
}

.audit-section {
  margin-top: 20px;
}

.dialog-footer {
  text-align: right;
}
</style>